package com.framework.network.nio;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;

/**
 * @author duanzhizhou
 * @date 2025/6/5
 */
public class Client {
    
    public static void main(String[] args) throws IOException {
        try (SocketChannel client = SocketChannel.open()) {
            client.connect(new InetSocketAddress("localhost", 8088));
            client.configureBlocking(false);
            for (int i = 0; i < 10; i++) {
                String msg = "hello " + i;
                ByteBuffer byteBuffer = ByteBuffer.wrap(msg.getBytes());
                while (byteBuffer.hasRemaining()) {
                    client.write(byteBuffer);
                }
            }
        }
    }
}
